package fr.inserm.umr915.vcfserver.bio.ucsc.pg;

import java.io.IOException;

import com.sleepycat.bind.tuple.TupleBinding;


import fr.inserm.umr915.vcfserver.bio.Chromosomes;
import fr.inserm.umr915.vcfserver.bio.Segment;
import fr.inserm.umr915.vcfserver.bio.berkeley.DatabaseManager;
import fr.inserm.umr915.vcfserver.xml.XmlStreamSerializer;

public class PersonalGenomeHandler extends DatabaseManager<PersonalGenome>
	{
	private String genome;
	private PersonalGenome.Binding dataBinding=null;
	private PersonalGenome.StaxSerializer stax=null;
	
	public PersonalGenomeHandler(String genome,Chromosomes chromosomes)
		{
		this.genome=genome;
		this.stax=new PersonalGenome.StaxSerializer(this.genome);
		this.dataBinding=new PersonalGenome.Binding(chromosomes);
		}
	
	@Override
	public XmlStreamSerializer<PersonalGenome> getXmlStreamSerializer()
		{
		return this.stax;
		}
	
	public String getGenome() {
		return genome;
		}
	
	@Override
	public TupleBinding< PersonalGenome> getDataBinding()
		{
		return this.dataBinding;
		}

	@Override
	public PersonalGenome parse(String line) throws IOException
		{
		PersonalGenome g= PersonalGenome.parse(getDelim().split(line));
		if(!acceptChromosome(g.getChrom())) return null;
		return g;
		}
	@Override
	public Segment getSegment(PersonalGenome o)
		{
		return new Segment(o.getChrom(),o.getChromStart(),o.getChromEnd());
		}
	}
